<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>

<!DOCTYPE html>
<html lang="zh-CN">
    <head>
        <meta charset="UTF-8">
        <%@ include file="/WEB-INF/views/include/head.jsp"%> 
        <link rel="stylesheet" href="${ctxStatic}/css/DateTimePicker.css">
        <link rel="stylesheet" href="${ctxStatic}/css/layerSm.css">
        <script>
            $(function(){
                $(".tabBox ul li").each(function(){
                    var index=$(this).index();
                    $(".tabBox ul li").eq(0).addClass("active");
                    $(this).click(function(){
                        $(this).addClass("active").siblings().removeClass("active");
                        $(".tabBoxSm > .tabBox").eq(index).stop(true).show().siblings().stop(true).hide();
                    });
                });
                //商铺国家  商铺城市  用户国家  用户城市  用户性别  用户角色
                $("#shopCountry,#styleCodes,#shopCity,#userCountry,#userCity,#sex,#role").select2();
            });
            //保存方法
            var saveForm={
                t:null,
                save:function(t){
                    $(t).attr("disabled",true);
                    this.t=t;
                    $("#inputForm").validate({
                        submitHandler: function() {
                            var params = $("#inputForm").serialize();
                            $.post("${ctx}/sys/shop/save",params,function(result){
                                tipParent(result.message);
                                if(result.statusCode==STATUSCODEOK){
                                    window.parent.frames[0].location.reload();
                                    closeWin(); 
                                }else{
                                    $(saveForm.t).attr("disabled",false);
                                }
                            },'json'); 
                        },
                        rules: {
                            shopName: {remote: "${ctx}/sys/shop/checkShopName?oldShopName=" + encodeURIComponent("${shop.shopName}")},
                            "user.loginName": {remote: "${ctx}/sys/shop/checkLoginName?oldLoginName=" + encodeURIComponent($('#oldLoginName').val())},
                        },
                        messages: {
                            shopName: {remote: '<spring:message code="shop_shopName_exist"/>'},
                            "user.loginName": {remote: '<spring:message code="shop_loginName_exist"/>'},
                        },
                        fail: function(element,e) {  
                            $(saveForm.t).attr("disabled",false);
                        }
                    });
                    $("#inputForm").submit(); 
                }
            }
            //城市联动
            function cityFun(t,id){
                var code=$(t).find("option:selected").attr("data-value");
                var param={"code":code};
                $.post("${ctx}/sys/shop/city",param,function(result){
                    var html="<option value=''><spring:message code='shop_saveregion'/></option>";
                    $.each(result,function(i,e){
                        html+="<option value='"+e.itemCode+"-"+e.itemValue+"'>"+e.itemName+"</option>";
                    });
                    $("#"+id).html(html);
                    $("#"+id).select2();
                },'json');
            }
        </script>
    </head>
    <body>
    <!--头部-->
        <div class="myshop clearfix">
            <c:choose>
                <c:when test="${shop.id!=null&&shop.id!=''}">
                <!--编辑店铺-->
                    <p class="myshoptop fl"><spring:message code="shop_editShop"/></p>
                </c:when>
                <c:otherwise>
                <!--新建店铺-->
                    <p class="myshoptop fl"><spring:message code="shop_creatShop"/></p>
                </c:otherwise>
            </c:choose>
            <div class="fr">
                <div class="topBtnClose" onclick="closeWin()">
                    <img src="${ctxStatic}/images/btn-close.png">
                </div>
            </div>
        </div>
        <div class="middle ">
            <div class="tabBox">
                <ul class="clearfix">
                    <li class="active"><spring:message code="shop_information"/></li>
                    <li><spring:message code="shop_management"/></li>
                </ul>
            </div>
            <c:set value="<%=ResourcesUtil.getConfig(\"user_sex\")%>" var="userSex" />
            <c:set value="<%=ResourcesUtil.getConfig(\"shop_country\")%>" var="shopCountry" />
            <c:set value="<%=ResourcesUtil.getConfig(\"shop_styleCategory\")%>" var="shopStyleCategory" />
            <form id="inputForm" method="post">
            <input type="hidden"  name="ognizationId"  value="-1">
            <input type="hidden"  name="id"  value="${shop.id }">
            <input type="hidden"  name="user.id"  value="${user.id }">
            <input type="hidden"  name="user.version"  value="${user.version }">
            <input type="hidden"  name="version"  value="${shop.version} ">
                <div class="tabBoxSm createH">
                    <div class="tabBox">
                        <div class="myshop_middle">
                            <div class="data clearfix">
                                <div class="ch fl haveToBox">
                                <!--店铺名称-->
                                    <p class="data_id"><spring:message code="shop_shopName"/></p>
                                    <input type="text" data-rule-required="true" maxlength="20" data-msg-required="<spring:message code="shop_saveShopName"/>" class="form-control" id="shopName" name="shopName" value="${shop.shopName }">
                                    <input type="hidden"  class="form-control" name="oldShopName" value="${shop.shopName }">
                                    <p class="haveTo">*</p>
                                </div>
                                <div class="ch fr haveToBox">
                                    <!--联系人-->
                                    <p class="data_id"><spring:message code="shop_contacts"/></p>
                                    <input type="text" data-rule-required="true" data-msg-required="<spring:message code="shop_saveShopContactPerson"/>" maxlength="20" class="form-control" name="contactPerson" value="${shop.contactPerson }">
                                    <p class="haveTo">*</p>
                                </div>
                            </div>
                            <div class="data clearfix">
                                <div class="ch fl">
                                    <div class="ch_middle fl haveToBox">
                                    <!--所在国家-->
                                        <p class="data_id"><spring:message code="shop_hostCountry"/></p> 
                                        <select class="sex" data-rule-required="true" data-msg-required="<spring:message code="shop_saveCountry"/>" id="shopCountry" name="shopCountry" onchange="cityFun(this,'shopCity')">
                                            <option value=""><spring:message code="shop_saveCountry"/></option>
                                            <c:forEach items="${fns:getDictList(shopCountry)}"   var="country">
                                                <option data-value="${country.itemValue}" <c:if test="${fn:split(shop.shopCountry, '-')[1] eq country.itemValue}">selected="selected"</c:if> value="${country.itemCode}-${country.itemValue}">${country.itemName}</option>
                                            </c:forEach>
                                        </select>
                                        <p class="haveTo">*</p>
                                    </div>
                                    <div class="ch_middle fr haveToBox">
                                        <!--所在地区-->
                                        <p class="data_id"><spring:message code="shop_region"/></p>
                                        <select class="sex" data-rule-required="true" data-msg-required="<spring:message code="shop_saveregion"/>" id="shopCity" name="shopCity" >
                                            <option value=""><spring:message code="shop_saveregion"/></option>
                                            <c:forEach items="${fns:getDictList(fn:split(shop.shopCountry, '-')[1])}" var="city">
                                                <option 
                                                    <c:if test="${fn:split(shop.shopCity, '-')[1] eq city.itemValue}">selected="selected"</c:if>  value="${city.itemCode}-${city.itemValue}">
                                                    ${city.itemName}
                                                </option>
                                            </c:forEach>
                                        </select>
                                        <p class="haveTo">*</p>
                                    </div>
                                </div>
                                <div class="ch fr">
                                <!--联系电话-->
                                    <p class="data_id"><spring:message code="shop_contactNumber"/></p>
                                    <input type="tel" class="form-control" maxlength="11" name="contactPhone"  value="${shop.contactPhone }"  data-rule-banjiao="true" data-msg-banjiao="<spring:message code="shop_pleaseInput_banjiao"/>"    >
                                </div>
                            </div>
                            <div class="data clearfix">
                                <div class="ch fl">
                                    <!--店铺地址-->
                                    <p class="data_id"><spring:message code="shop_address"/></p>
                                    <textarea class="shopint"   maxlength="100" name="shopAddress" >${shop.shopAddress }</textarea>
                                </div>
                                <div class="ch fr ">
                                    <div class=" data clearfix">
                                        <!--联系传真-->
                                        <p class="data_id"><spring:message code="shop_fax"/></p>
                                        <input type="text" class="form-control" maxlength="50" name="contactFax"  value="${shop.contactFax }" data-rule-banjiao="true" data-msg-banjiao="<spring:message code="shop_pleaseInput_banjiao"/>" >
                                    </div>
                                    <div class=" clearfix haveToBox">
                                    <!--联系邮箱-->
                                        <p class="data_id"><spring:message code="shop_mailbox"/></p>
                                        <input type="text"   class="form-control"   data-rule-email="true"  data-rule-required="true" data-msg-email="<spring:message code="shop_saveEmail"/>" data-msg-required="<spring:message code="shop_saveEmail"/>" maxlength="50" name="contactEmail"  value="${shop.contactEmail }">
                                        <p class="haveTo">*</p>
                                    </div>
                                </div>
                            </div>
                            <div class=" clearfix">
                                <div class="ch fl clearfix">
                                    <div class="data clearfix">
                                        <!--店铺简介-->
                                        <p class="data_id"><spring:message code="shop_shopProfile"/></p>
                                        <textarea class="shopint"  maxlength="200" name="shopDiscribe" >${shop.shopDiscribe }</textarea>
                                    </div>
                                    <div class="data clearfix haveToBox">
                                        <!--开户银行-->
                                        <p class="data_id"><spring:message code="shop_bankAccount"/></p>
                                        <input type="text" data-rule-required="true" class="form-control"  data-msg-required="<spring:message code="shop_bankAccount"/>"  maxlength="20" name="bankName"  value="${shop.bankName }">
                                    	<p class="haveTo">*</p>
                                    </div>
                                    <div class="data clearfix haveToBox">
                                        <!--银行账号-->
	                                    <p class="data_id " ><spring:message code="shop_bankAccountNO"/></p>
	                                    <input type="tel" data-rule-required="true"  data-msg-required="<spring:message code="shop_bankAccountNO"/>"  class="form-control" maxlength="30" name="bankAccountNo" data-rule-nonnegativeInteger="true"  data-msg-nonnegativeInteger="<spring:message code="shop_saveBankAccountNO"/>" value="${shop.bankAccountNo }">
	                                    <p class="haveTo">*</p>
                                    </div>
                                    <!--经营款式-->
                                    <div class="clearfix haveToBox">
                                        <p class="data_id"><spring:message code="shop_managementStyle"/></p>
				                        <select class="sex mult" id="styleCodes" multiple="multiple" name="styleCodes" data-rule-required="true" data-msg-required="<spring:message code="shop_plsChooseAGategory"/>">
				                            <%-- <option value=""><spring:message code="myMaterial_pleaseChoosed"/></option> --%>
				                            <c:forEach items="${fns:getDictList(shopStyleCategory)}"   var="style">
				                                 <option  value="${style.itemCode}-${style.itemValue}"
				                                  <c:forEach items="${shopStyleSelectList}" var="shopStyle" >
				                                    <c:if test="${fn:split(shopStyle.itemId,'-')[1] eq style.itemValue}">selected="selected"</c:if>
				                                   </c:forEach>
				                                  > 
				                                    ${style.itemName}
				                                </option> 
				                            </c:forEach>
				                        </select>
				                        <p class="haveTo">*</p>
                                    </div>
                                </div>
                                <div class="ch fr clearfix">
                                    <div class="ch_top clearfix haveToBox">
                                        <!--店铺标识-->
                                        <p class="data_id"><spring:message code="shop_shopLogo"/></p>
                                        <div class="square" style="height:240px;">
                                            <input type="hidden" id="nameImage" data-rule-required="true" data-msg-required="<spring:message code="shop_saveShopLogo"/>" name="shopLogo" value="${shop.shopLogo}" htmlEscape="false" maxlength="255" class="input-xlarge"/> 
                                            <sys:ckfinder input="nameImage" type="images" uploadPath="/shopLogo" selectMultiple="false" maxWidth="200" maxHeight="200"/>
                                        </div>
                                        <p class="haveTo">*</p>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="tabBox none">
                        <div class="myshop_middle">
                            <div class="data clearfix">
                                <div class="ch fl">
                                    <div class="ch_middle fl haveToBox">
                                        <!--姓-->
                                        <p class="data_id"><spring:message code="shop_surname"/></p>
                                        <input type="text" data-rule-required="true"   data-msg-required="<spring:message code="shop_saveUserFirstName"/>" maxlength="20" name="user.firstName" class="form-control fam"  value="${user.firstName }">
                                        <p class="haveTo">*</p>
                                    </div>
                                    <div class="ch_middle fr haveToBox">
                                        <!--名字-->
                                        <p class="data_id"><spring:message code="shop_name"/></p>
                                        <input type="text"  data-rule-required="true"  data-msg-required="<spring:message code="shop_saveUserLastName"/>"  maxlength="20" name="user.lastName" class="form-control fam"  value="${user.lastName }">
                                        <p class="haveTo">*</p>
                                    </div>
                                </div>
                                <div class="ch fr">
                                    <!--联系电话-->
                                    <p class="data_id"><spring:message code="shop_contactNumber"/></p>
                                    <input type="text" name="user.telNo" class="form-control" maxlength="20"  value="${user.telNo}" data-rule-banjiao="true" data-msg-banjiao="<spring:message code="shop_pleaseInput_banjiao"/>" >
                                </div>
                            </div> 
                            <div class="data clearfix">
                                <div class="ch fl">
                                    <div class="ch_middle fl haveToBox">
                                    <!--登录名-->
                                        <p class="data_id"><spring:message code="shop_loginName"/></p>
                                        <input type="text" id="loginName" name="user.loginName" maxlength="20" data-rule-required="true" data-msg-required="<spring:message code="shop_saveUserLoginName"/>"  class="form-control fam"  value="${user.loginName }">
                                        <input type="hidden" id="oldLoginName" name="oldLoginName" value="${user.loginName}" maxlength="20"  class="form-control fam" placeholder="<spring:message code="shop_saveUserPassWord"/>">  
                                        <p class="haveTo">*</p>
                                    </div>
                                    <c:choose>
                                        <c:when test="${shop.id!=null&&shop.id!=''}"></c:when>
                                        <c:otherwise>
                                            <div class="ch_middle fr haveToBox">
                                            <!--登录密码-->
                                                <p class="data_id"><spring:message code="shop_password"/></p>
                                                <input type="text" name="user.newPassword"  data-rule-required="true" data-msg-required="<spring:message code="shop_password"/>" class="form-control fam"  value="" maxlength="20" data-rule-banjiao="true" data-msg-banjiao="<spring:message code="shop_pleaseInput_banjiao"/>">
                                                <input type="hidden" id="password" name="password" value="${user.password}" class="form-control fam" >
                                                <p class="haveTo">*</p>
                                            </div>
                                        </c:otherwise>
                                    </c:choose>
                                </div>
                                <div class="ch fr">
                                <!--联系传真-->
                                    <p class="data_id"><spring:message code="shop_fax"/></p>
                                    <input type="text" name="user.faxNo" class="form-control" maxlength="20"  value="${user.faxNo }" data-rule-banjiao="true" data-msg-banjiao="<spring:message code="shop_pleaseInput_banjiao"/>" >
                                </div>
                            </div> 
                            <div class="data clearfix">
                                <div class="ch fl haveToBox">
                                <!--性别-->
                                    <p class="data_id"><spring:message code="shop_sex"/></p>
                                    <select id="sex" class="sex" name="user.sex" data-rule-required="true" data-msg-required="<spring:message code="shop_saveUserSex"/>">
                                        <option value=""><spring:message code="shop_saveUserSex"/></option>
                                        <c:forEach items="${fns:getDictList(userSex)}" var="sex">
                                            <option  <c:if test="${fn:split(user.sex,'-')[1] eq sex.itemValue}">selected="selected"</c:if> value="${sex.itemCode}-${sex.itemValue}">
                                                ${sex.itemName}
                                            </option>
                                        </c:forEach>
                                    </select> 
                                    <p class="haveTo">*</p>
                                </div>
                                <div class="ch fr haveToBox">
                                    <!--Email-->
                                    <p class="data_id"><spring:message code="shop_email"/></p>
                                    <input type="text" name="user.email" data-rule-required="true" data-rule-email="true" data-msg-email="<spring:message code="shop_saveEmail"/>" data-msg-required="<spring:message code="shop_saveEmail"/>"  class="form-control" maxlength="50"  value="${user.email }">
                                    <p class="haveTo">*</p>
                                </div>
                            </div> 
                            <div class="data clearfix">
                                <div class="ch fl clearfix">
                                <!--出生日期-->
                                    <p class="data_id"><spring:message code="shop_bringDay"/></p>
                                    <div class="timeBox">
                                        <input type="text" name="user.birthDate" data-field="date" maxlength="50" class="form-control time" readonly value="<fmt:formatDate value="${user.birthDate}" pattern="yyyy-MM-dd"/>"  >
                                    </div>
                                </div>
<!--                                 <div class="ch fr clearfix"> -->
<!--                                     <div class="ch_middle fl haveToBox"> -->
<!--                                         所在国家 -->
<%--                                         <p class="data_id"><spring:message code="shop_hostCountry"/></p> --%>
<%--                                         <select class="sex" id="userCountry" name="user.country" id="user.country"  data-rule-required="true" data-msg-required="<spring:message code="shop_saveCountry"/>" onchange="cityFun(this,'userCity')"> --%>
<%--                                             <option value=""><spring:message code="shop_saveCountry"/></option> --%>
<%--                                             <c:forEach items="${fns:getDictList(shopCountry)}"   var="country"> --%>
<%--                                                 <option   data-value="${country.itemValue}" <c:if test="${fn:split(user.country, '-')[1] eq country.itemValue}">selected="selected"</c:if> value="${country.itemCode}-${country.itemValue}">${country.itemName}</option> --%>
<%--                                             </c:forEach> --%>
<!--                                         </select> -->
<!--                                         <p class="haveTo">*</p> -->
<!--                                     </div> -->
<!--                                     <div class="ch_middle fr haveToBox"> -->
<!--                                         所在城市 -->
<%--                                         <p class="data_id"><spring:message code="shop_region"/></p> --%>
<%--                                         <select class="sex" id="userCity" name="user.city" data-rule-required="true"data-msg-required="<spring:message code="shop_saveregion"/>"> --%>
<%--                                             <option value=""><spring:message code="shop_saveregion"/></option> --%>
<%--                                             <c:forEach items="${fns:getDictList(fn:split(user.country, '-')[1])}" var="city"> --%>
<!--                                                 <option  -->
<%--                                                     <c:if test="${fn:split(user.city, '-')[1] eq city.itemValue}">selected="selected"</c:if>  value="${city.itemCode}-${city.itemValue}"> --%>
<%--                                                     ${city.itemName} --%>
<!--                                                 </option> -->
<%--                                             </c:forEach> --%>
<!--                                         </select> -->
<!--                                         <p class="haveTo">*</p> -->
<!--                                     </div> -->
<!--                                 </div> -->
                            </div> 
                            <div class="data clearfix" >
                                <div class="ch fl">
                                <!--手机号码-->
                                    <p class="data_id"><spring:message code="shop_iphoneNum"/></p>
                                    <input type="text" name="user.mobile" maxlength="11" class="form-control"  value="${user.mobile}" data-rule-nonnegativeInteger="true"  data-msg-nonnegativeInteger="<spring:message code="shop_pleaseInput_contactPhone"/>">
                                </div>
                                <div class="ch fr haveToBox">
                                    <!--人员角色-->
                                    <p class="data_id"><spring:message code="shop_personnelrole"/></p>
                                    <select class="sex" data-rule-required="true" data-msg-required="<spring:message code="shop_saveRoleName"/>" id="role" name="user.role.id" >
                                        <option value=""><spring:message code="shop_saveRoleName"/></option>
                                         <c:forEach items="${allRoles}" var="allRole">
                                            <option <c:if test="${user.role.id eq allRole.id}">selected="selected" </c:if>  value="${allRole.id}">${allRole.roleName}</option>
                                         </c:forEach>
                                    </select>
                                    <p class="haveTo">*</p>
                                </div>
                            </div> 
                            <div class=" clearfix">
                                <div class="ch fl">
                                    <!--详细地址-->
                                    <p class="data_id"><spring:message code="shop_detailedAddress"/></p>
                                    <textarea class="shopint" name="user.address" maxlength="100"  >${user.address}</textarea>
                                </div>
                                <div class="ch fr">
                                    <!--备注-->
                                    <p class="data_id"><spring:message code="shop_remarks"/>
                                    <span class="txtRg">(0/100)</span>
                                    </p>
                                    <textarea class="shopint" name="user.remarks" maxlength="100"  >${user.remarks}</textarea>
                                </div> 
                            </div>  
                        </div>
                    </div>
                </div>
            </form>
            <div class="twobtn" style="margin-top:0;">
                <div class="onebtn clearfix" style="text-align:center;">
                <shiro:hasPermission name="sys:shop:edit">
                    <button class="btn save fl" style="float:none;" type="button" onclick="saveForm.save(this)"><spring:message code="common_save"/></button>
                </shiro:hasPermission>
                </div>
            </div>
        </div>
        <div id="dtBox1"></div>
        <script src="${ctxStatic}/DateTimePicker/DateTimePicker.js"></script>
        <script>
            var windowH = window.innerHeight
                ||document.documentElement.clientHeight
                ||document.body.clientHeight
            $('.middle').css('height',windowH - 40);
            $(document).ready(function() {
                $("#dtBox1").DateTimePicker({
                    dateFormat: "yyyy-MM-dd",
                    parentElement: ".timeBox",
                });
            });
        </script>
    </body>
</html>